/* JAVASCRIPT GOOGLE MAP */

var map;

google.maps.event.addDomListener(window, 'load', initialize);

function initialize_map() {
	var latlng = new google.maps.LatLng(43.716005, 7.263872);
	var myOptions = {
		zoom: 3,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.HYBRID
		};
	map = new google.maps.Map(document.getElementById("map_canvas"),
			myOptions);
}

function geocodeAndSave(meeting) {
	var geocoder = new google.maps.Geocoder();
	geocoder.geocode({address:meetings_tmp[meeting]["address"]}, 
			function (response) {
				if (response != null) {
					meetings_tmp[meeting]["address"] = response[0]["geometry"]["location"];
					meetings.push(meetings_tmp[meeting]);
					addMarkerAndShow(meetings.length - 1);
				} else {
					alert("Adresse inconnue");
				}
			});
}

function addMarkerAndShow(meeting) {
	var marker = new google.maps.Marker({
        position: meetings[meeting]["address"],
        map: map,
        animation: google.maps.Animation.DROP,
        title: meetings[meeting]["name"]});
	google.maps.event.addListener(marker, 'click', function() {
    	map.setCenter(this.position);
        map.setZoom(18);
        fill(meetings[meeting]["name"], 'meetings');
        draw_chart_themes(meetings[meeting]["themes"]["theme"], meetings[meeting]["name"]);
    });
	map.setCenter(meetings[meeting]["address"]);
}

function addMarker(center) {
	var latlng = new google.maps.LatLng(centers[center]["latitude"], centers[center]["longitude"]);
	var image = "images/building-ico.png";
	var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: image, 
        animation: google.maps.Animation.DROP, 
        title: centers[center]["libelle"]});
	google.maps.event.addListener(marker, 'click', function() {
    	map.setCenter(this.position);
        map.setZoom(18);
        getCenterInfo(center);
        switch_select("#filter_centers", center+1);
    });
	map.setCenter(latlng);
}

function zoom_out() {
	var latlng = new google.maps.LatLng(43.716005, 7.263872);
	map.setCenter(latlng);
	map.setZoom(2);
}